//
//  YSProductPoolBigModeHeaderView.m
//  Yueshi
//
//  Created by Northwan on 15/10/13.
//  Copyright © 2015年 悦食中国. All rights reserved.
//

#import "YSProductPoolBigModeHeaderView.h"

//#define HeaderImgScaleHeight (SCREENW-YSPublicXInset*2)/2.73
#define kTitleFont 14

@interface YSProductPoolBigModeHeaderView()
@property (strong, nonatomic) UIImageView *iconView;
@property (strong, nonatomic) UILabel *titleLabel;

@property (strong, nonatomic) UIView *titleView;
@property (strong, nonatomic) UIButton *imageBtn;

@end



@implementation YSProductPoolBigModeHeaderView

-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if(self){
        [self setBackgroundColor:[UIColor whiteColor]];
        UIImageView *iconView  = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, SCREENW,SCREENW * 350 /750)];
        [self addSubview:iconView];
        _iconView = iconView;
        
        UIView *titleView = [[UIView alloc] init];
        titleView.layer.borderColor = [ThemeColor CGColor];
        titleView.layer.borderWidth = 0.5f;
        titleView.frame = CGRectMake(YSPublicXInset, CGRectGetMaxY(self.iconView.frame) + YSPublicXInset *2, SCREENW-YSPublicXInset*2, 15);
        [self addSubview:titleView];
        _titleView = titleView;
        
        UIButton *imageBtn = [[UIButton alloc] init];
        imageBtn.backgroundColor = [UIColor whiteColor];
        UIImage *image = [UIImage imageNamed:@"german-icon"];
        [imageBtn setImage:image forState:UIControlStateNormal];
        imageBtn.frame = CGRectMake(SCREENW/2 - image.size.width/2 - 5, - image.size.height/2, image.size.width + 10, image.size.height);
        [self addSubview:imageBtn];
        _imageBtn = imageBtn;
        
        UILabel *titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(YSPublicXInset, image.size.height/2 +YSPublicXInset, titleView.width - YSPublicXInset*2, 15)];
        [titleLabel setFont:SYS_FONT(kTitleFont)];
        [titleLabel setNumberOfLines:0];
        [titleLabel setTextColor:HEXColor(@"#333333")];
        [titleView addSubview:titleLabel];
        _titleLabel = titleLabel;
    }
    return self;
}

-(void)setTopInfo:(NSString *)topInfo{
    [self setInfoWithTopImage:nil topInfo:topInfo];
}

-(void)setInfoWithTopImage:(NSString *)topImage topInfo:(NSString *)topInfo{
    CGFloat titleViewY = YSPublicXInset *2;
    if(!ISBLANK(topImage)){
        [self.iconView setImageURLStr:topImage];
        titleViewY += CGRectGetMaxY(self.iconView.frame);
    }else{
        [self.iconView removeFromSuperview];
    }

    self.titleView.y = titleViewY;
    CGSize size = [topInfo sizeWithFont:SYS_FONT(kTitleFont) constrainedToSize:CGSizeMake(self.titleView.width - YSPublicXInset, MAXFLOAT)];
    [self.titleLabel setHeight:size.height];
    [self.titleLabel setText:topInfo];
    

    self.imageBtn.y = self.titleView.y  - self.imageBtn.imageView.image.size.height/2;
    self.titleLabel.y = self.imageBtn.imageView.image.size.height/2 + YSPublicXInset;
    self.titleView.height = CGRectGetMaxY(self.titleLabel.frame) + 17;

    
    UIView *spliteView = [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(self.titleView.frame)+YSPublicXInset, SCREENW, YSPublicXInset)];
    [spliteView setBackgroundColor:PUBLIC_BG];
    [self addSubview:spliteView];
    
    [self setFrame:CGRectMake(0, 0, SCREENW, CGRectGetMaxY(spliteView.frame))];
}


@end
